<template>
 <div style="text-align: left; background-color: #f6f7f9; height:670px;">
   <!-- 顶部导航 -->
   <van-sticky>
     <van-nav-bar title="新增地址" left-arrow @click-left="$router.go(-1)">
     </van-nav-bar>
   </van-sticky>
   <van-address-edit
       :area-list="areaList"
       :address-info="addressInfo"
       show-delete
       show-set-default
       show-search-result
       :search-result="searchResult"
       :area-columns-placeholder="['请选择', '请选择', '请选择']"
       @save="onSave"
   />
 </div>

</template>
<script>
import {areaList} from '@vant/area-data'
export default {
  name: "AddressAddNew",
  data() {
    return {
      areaList,
      searchResult: [],
      addressInfo:{}
    };
  },
  methods: {
    onSave(content) {
      console.log("addressDetails", content);
      let url = 'http://localhost:9080/addresses/add-new';
      let addressDetails = this.qs.stringify(content, {arrayFormat: 'repeat'});
      console.log('addressDetails = ' + addressDetails);
      this.axios
          .create({'headers': {'Authorization': localStorage.getItem('jwt')}})
          .post(url, addressDetails).then((response) => {
        let responseBody = response.data;
        console.log(responseBody);
        if (responseBody.state == 20000) {
          this.$toast.success('添加地址成功!');
          this.$router.replace("/user/address");
        }else{
          this.$toast.fail(responseBody.message);
        }
      });
    },
  },
}
</script>

<style scoped>

</style>
